/*
 * @Author: 李瑞清
 * @Date: 2023-02-24 17:28:15
 * @LastEditors: 李瑞清 alger_li@163.com
 * @LastEditTime: 2023-04-12 10:11:14
 * @FilePath: \oms\scprit\followup\app\patientManager\addPatient.js
 * @Description: 
 */
/**
 * @ author: 汪孟苹
 */
define(['jquery', "bbcare",
	"scprit/followup/app/patientManager/addPatient.servers.js",
	"scprit/followup/app/patientManager/addPatient.ui.js",
	"scprit/followup/app/patientManager/addPatient.event.js"
],
	function ($, $bb, $addPatientServers, $addPatientUi, $addPatientEvent) {
		var addPatient = {}
		/**
		 * 请求队列成功后的回调函数
		 */
		var getQueuesCallback = function (data) {
			$addPatientUi.queues({	// 队列列表
				id: "queueList",
				list: data.rows,
			})
			var pageParams = $bb.getPageParams()
			// var topbars = [
			// 	{
			// 		"icon":"fa fa-times",
			// 		"name":"关闭",
			// 		"params":pageParams,
			// 		"callback":$addPatientEvent.onCloseSelect
			// 	}
			// ];
			// $bb.toolbar(topbars);
			var params = $addPatientServers.getInitQueueParams(data)
			/* 点击哪个队列就渲染哪个队列的详细建档问卷 */
			$("#queueList .queue-card").unbind("click")
			$("#queueList .queue-card").click($addPatientEvent.onQueueNavSelect)
			if (pageParams && pageParams.followQueueId) {
				var index = $addPatientServers.getCurQueue(data.rows, pageParams.followQueueId)
				$("#queueList .queue-card").eq(index).click()
				$("#queueList").css({ "display": "none" })
			} else {
				$("#queueList .queue-card:first-child").click()
			}

			// 是否是从 his 过来的 
			if (pageParams.queueid && !pageParams.oprInfo) {
				function renderHisData () {
					setTimeout(function () {
						if ($('#queueList .queue-card')) {
							$('#queueList').hide()
							$addPatientEvent.renderHisData(pageParams)
						} else {
							renderHisData()
						}
					}, 100)
				}
				renderHisData()
			}



		}



		/**
		 * 建档页面初始化
		 */
		addPatient.init = function () {
			$addPatientServers.ajaxQueueList(getQueuesCallback)
		}

		return addPatient
	})